export default {
	isJiess: true,
	name: 'Custom',
	setup({ midder, hook, Tree }) {
		const { columns = [] } = midder.proxy;
		const gData = hook.$m.$ref([...columns]);
		this.add({
			draggable: true,
			is: Tree,
			'node-key': 'key',
			'show-checkbox': true,
			'check-strictly': true,
			'default-checked-keys': columns.filter((o) => !o.hidden).map((o) => o.key),
			data: { $proxy: gData },
			on: {
				// 'node-drag-start'(node, ev) {
				// 	console.log('drag start', node);
				// },
				// 'node-drag-enter'(draggingNode, dropNode, ev) {
				// 	console.log('tree drag enter: ', dropNode.label);
				// },
				// 'node-drag-leave'(draggingNode, dropNode, ev) {
				// 	console.log('tree drag leave: ', dropNode.label);
				// },
				// 'node-drag-over'(draggingNode, dropNode, ev) {
				// 	console.log('tree drag over: ', dropNode.label);
				// },
				// 'node-drag-end'(draggingNode, dropNode, dropType, ev) {
				// 	console.log('tree drag end: ', dropNode && dropNode.label, dropType);
				// },
				'node-drop'(draggingNode, dropNode, dropType, ev) {
					// console.log('tree drop: ', dropNode.label, dropType);
					// 解除key与元素间的绑定关系
					proxy.columns = [];
					const timer = setTimeout(() => {
						clearTimeout(timer);
						proxy.columns = [...gData.value];
					})
				},
				check(_, { checkedKeys }) {
					proxy.columns = columns.map((o) => {
						o.hidden = !checkedKeys.includes(o.key);
						return o;
					});
				},
			},
			allowDrop(draggingNode, dropNode, type) {
				return type !== 'inner';
			},
			allowDrag(draggingNode) {
				return draggingNode.label !== '操作';
			}
		})
	}
};